home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 1992 August / info-mac-1992.iso / Utilities (util) / MacGREP / mac-grep-02.abstract < prev    next >
Internet Message Format  |  1992-08-29  |  5KB

  1. Date: Sun, 21 Apr 91 21:04 CDT
  2. From: "Ken R. Lunde" <KLUNDE@vms.macc.wisc.edu>
  3. Subject: util/macgrep-02.hqx
  4.  
  5. util/macgrep-02.hqx
  6.  
  7. MacGREP 0.2
  8.  
  9.      I spent quite a while trying to locate a program on the Macintosh which
  10. performs the same function as "grep" on UNIX systems, namely that one can
  11. output from one file specific lines, which match a specified pattern, to
  12. another file -- a sort of extracting of lines. I finally found a program which
  13. does this on page 117 and 165 of "The C Programming Language" (second edition)
  14. by Kernighan and Ritchie, 1988, Prentice Hall. What I simply did was to port
  15. this small program to the Macintosh while still retaining the UNIX-style
  16. command-line argument function. I also used a modified version of the function
  17. found on page 279 of "Algorithms in C" by Sedgewick, 1990, Addison-Wesley. The
  18. major modifications were to make the program work with 2-byte encoded Japanese
  19. text in SHIFT-JIS code.
  20.      As many may know, "grep" is a UNIX function which stands for "global
  21. regular expression print," and is used to print lines from files based on
  22. pattern matching. This particular version of grep only has a few features, and
  23. I plan to add more in the near future.
  24.      Now for the instructions. This program, once launched, displays a window
  25. called "console," and a dialog with 3 basic parts:
  26.  
  27. 1) Standard Input
  28. 2) Standard Output
  29. 3) Command Line
  30.  
  31. 1) Standard Input: 2 choices are given, namely console and file. I wrote the
  32. program so that it takes its input from a file, so be sure to check the file
  33. radio button. At that point you will be prompted to locate the file you wish
  34. to use as input (using the standard Macintosh file system).
  35.  
  36. 2) Standard Output: 4 choices are given, namely console, file, console+file,
  37. and console+printer. Console means that the output of the program will be
  38. displayed in the window called "console." If you choose the output to be placed
  39. in a file, you will be prompted for the file name (using the standard Macintosh
  40. file system). Perhaps the most useful radio button is console+file since it
  41. outputs to both the window and to a file. Note that the number of lines matching
  42. the pattern is also output. This information is appended at the end.
  43.  
  44. 3) Command Line: The first item in the text window is the name of the program
  45. (I call it MacGREP). There are two optional flags you can use:
  46.  
  47. -n   This flag will also print the line number of the input file from which the
  48.      line was taken.
  49.  
  50. -x   This flag does an inverse pattern match, namely that all lines which do not
  51.      match the pattern will be output.
  52.  
  53. The only required item (besides the program name which is placed in the text
  54. window by default) is the pattern. This program accepts a single string as a
  55. search pattern. This means you can search for individual letters, parts of a
  56. word, or whole words. It has been written so that it accepts Japanese, and
  57. handles it correctly (the normal algorithms for grep won't).
  58.      I would like to mention that the TYPE of the output file (if so chosen)
  59. will be TEXT, but the CREATOR will be ????. This means that in order to view
  60. the ouput of the program you must first launch your favorite text editor or
  61. word processor, then choose OPEN. Double-clicking the file won't open it
  62. (unless you are running an application substitution program like HandOffII).
  63.      Programmer's note: I used the ccommand function described on page 171 of
  64. the Think C Standard Libraries Reference. This function handles the command-line
  65. argument handling, and displays the window and dialog. It is quite useful for
  66. running UNIX-based programs on the Macintosh. The source for MacGREP is
  67. included with this bundle.
  68.      Please send your comments and suggestions to me at klunde@macc.wisc.edu.
  69. I just ported this program yesterday (4/18/91), and I realize that it needs
  70. more features. I wrote it as a tool for extracting lines from lists of Japanese
  71. words which contain a specific Chinese character (or characters). I will supply
  72. source code upon request. You may distribute the program and its source code
  73. freely as long as ALL of the documentation is included (application, README,
  74. and source code). Parts of this program are copyright Symantec Corporation as
  75. I used Think C 4.0.2 as the development platform.
  76.      This program has been stuffed and binhexed. Enjoy!
  77.  
  78. Ken R. Lunde
  79. klunde@macc.wisc.edu
  80.  
  81. P.S. A copy of this file will be placed as a README file along with the program
  82. so that one will always have the instructions handy.
  83.  
  84.  
  85.